export default {
  inserted(el, binding) {
    const value = binding.value || {}
    const {
      delay, // 延时时间
      evtName = 'click', // 事件名
      evt // 事件
    } = value
    const throttle = (fn, delay = 500) => {
      let timer = null
      return function () {
        if (timer) {
          return
        }
        timer = setTimeout(() => {
          fn.apply(this, arguments)
          timer = null
        }, delay)
      }
    }
    el.addEventListener(
      evtName,
      throttle(function (e) {
        evt && evt()
      }, delay)
    )
  }
}
